<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>这是将所有单词首字母变为大写</title>
</head>
<body>
<script type="text/javascript">
    var sentence = 'good afternoon, mr mike.';

function toUpper(str) {
var arr =str.split(" ");
for(var i=0;i<arr.length;i++)
{
arr[i] = arr[i].charAt(0).toUpperCase() + arr[i].slice(1);
str = arr.join(" ");
}
    return str;}

    document.write(toUpper(sentence));
</script>
</body>
</html>